package com.salton123.feature.multistatus;

import android.view.View;

import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import com.salton123.arch.view.IMultiStatusView;
import com.salton123.feature.IFeature;
import com.salton123.saltonframework.R;
import com.salton123.ui.base.IComponentLife;

/**
 * User: newSalton@outlook.com
 * Date: 2019/12/11 17:18
 * ModifyTime: 17:18
 * Description:
 */
public class MultiStatusFeature implements IFeature, Callback.OnReloadListener, IMultiStatusView {
    public IComponentLife mIComponentLife;
    //状态页管理
    public LoadService mBaseLoadService;

    public MultiStatusFeature(IComponentLife componentLife) {
        this.mIComponentLife = componentLife;
    }

    @Override
    public void onBind() {
        LoadSir.Builder builder = new LoadSir.Builder()
                .addCallback(getInitStatus())
                .addCallback(getEmptyStatus())
                .addCallback(getErrorStatus())
                .addCallback(getLoadingStatus())
                .setDefaultCallback(getInitStatus().getClass());
        mBaseLoadService = builder.build().register(mIComponentLife.getRootView()
                .findViewById(R.id.salton_id_content_layout), this);
    }

    public Callback getInitStatus() {
        return new InitStatus();
    }

    public Callback getLoadingStatus() {
        return new LoadingStatus();
    }

    public Callback getErrorStatus() {
        return new ErrorStatus();
    }

    public Callback getEmptyStatus() {
        return new EmptyStatus();
    }

    @Override
    public void onUnBind() {
    }

    @Override
    public void onReload(View v) {
    }

    @Override
    public void showInitLoadView() {
        if (mBaseLoadService != null) {
            mBaseLoadService.showCallback(getInitStatus().getClass());
        }
    }

    @Override
    public void showNoDataView() {
        if (mBaseLoadService != null) {
            mBaseLoadService.showCallback(getEmptyStatus().getClass());
        }
    }

    @Override
    public void showTransLoadingView() {
        if (mBaseLoadService != null) {
            mBaseLoadService.showCallback(getLoadingStatus().getClass());
        }
    }

    @Override
    public void showNetWorkErrView() {
        if (mBaseLoadService != null) {
            mBaseLoadService.showCallback(getErrorStatus().getClass());
        }
    }

    @Override
    public void showSuccessView() {
        if (mBaseLoadService != null) {
            mBaseLoadService.showSuccess();
        }
    }
}
